package com.jnetwork.servlet.idea;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jnetwork.exception.DAOExcepcion;
import com.jnetwork.modelo.Idea;
import com.jnetwork.modelo.Usuario;
import com.jnetwork.negocio.GestionIdea;

/**
 * Servlet implementation class IdeaEvaluarServlet
 */
@WebServlet("/IdeaEvaluarServlet")
public class IdeaEvaluarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public IdeaEvaluarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id = (String)request.getAttribute("id");
		String strEstadoIdea = request.getParameter("txtEstadoIdea");
		String strIdAsesor = request.getParameter("idAsesor");
		GestionIdea negocio = new GestionIdea();
		try {
			Integer ideaId = Integer.parseInt(id);
			Integer asesorId = Integer.parseInt(id);
			Boolean evaluacion = negocio.evaluar(ideaId, strEstadoIdea, asesorId);
			request.setAttribute("evaluacion", evaluacion);
			request.setAttribute("id_idea", id);
			
			RequestDispatcher rd = request.getRequestDispatcher("idea_evaluar.jsp");
			rd.forward(request, response);
			
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("ERROR_MENSAJE", e.getMessage());
			RequestDispatcher rd = request
					.getRequestDispatcher("ideas_buscar.jsp");
			rd.forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String id = (String)request.getAttribute("id");
		String strEstadoIdea = request.getParameter("txtEstadoIdea");
		String strIdAsesor = request.getParameter("idAsesor");
		GestionIdea negocio = new GestionIdea();
		try {
			Integer ideaId = Integer.parseInt(id);
			Integer asesorId = Integer.parseInt(id);
			Boolean evaluacion = negocio.evaluar(ideaId, strEstadoIdea, asesorId);
			request.setAttribute("evaluacion", evaluacion);
			request.setAttribute("id_idea", id);
			
			RequestDispatcher rd = request.getRequestDispatcher("idea_evaluar.jsp");
			rd.forward(request, response);
			
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("ERROR_MENSAJE", e.getMessage());
			RequestDispatcher rd = request
					.getRequestDispatcher("ideas_buscar.jsp");
			rd.forward(request, response);
		}
		
	}

}
